using System;
using System.Collections;
using System.Collections.Generic;
using UMC.Web;
using UMC.WorkFlow.Entities;

namespace UMC.WorkFlow
{


    [Apiumc("WorkFlow", "Flow", Auth = WebAuthType.Guest, Desc = "流程实例流程图")]
    class WorkFlowFlowActivity : WebActivity
    {
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var InstanceId = UMC.Data.Utility.UInt64Parse(this.AsyncDialog("InstanceId", "none")).Value;

            var type = this.AsyncDialog("Type", request.IsApp ? "App" : "PC");
            switch (type)
            {
                case "App":
                    response.Redirect(new Uri(request.Url, $"/UMC/flowchart.html?Key={InstanceId}"));
                    break;
                case "Flow":
                    {

                        var task = TaskManager.Instance(InstanceId);
                        if (task == null)
                        {
                            response.Redirect(new WebMeta().Put("Result", TaskManager.Form(InstanceId)));

                        }
                        else
                        {

                            response.Redirect(new WebMeta().Put("Result", task));
                        }
                    }
                    break;
                default:
                    {
                        var task = TaskManager.Instance(InstanceId);
                        if (task == null)
                        {
                            this.Context.Send("Flow", new WebMeta().Put("Result", TaskManager.Form(InstanceId)), true);

                        }
                        else
                        {

                            this.Context.Send("Flow", new WebMeta().Put("Result", task), true);
                        }
                    }
                    break;

            }


        }


    }
}